package Basic;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class MyThread implements Runnable {
    private String name;//线程名
    private File file;//文件名
    private long begin;//起始位置
    private long end;//读取的结束位置
    public MyThread(String name, File file, long begin, long end) {
        this.name = name;
        this.file = file;
        this.begin = begin;
        this.end = end;
    }

    @Override
    public void run() {
        RandomAccessFile raf = null;
        try {
            raf = new RandomAccessFile(file, "rw");
            raf.seek(begin);// raf指针定位到最开始
            while (begin <= end) {//还没到最后，则继续
                int i = 255 - raf.read();
                raf.seek(raf.getFilePointer() - 1);// 或raf.seek(begin)
                raf.write(i);
                begin++;
            }
            System.out.println(name + "拷贝完成!");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            IOUtils.closeRandomAccessFile(raf);
        }
    }
}
